//
//  LeftViewController.m
//  HumorousSript
//
//  Created by 孟令博 on 15/6/19.
//  Copyright (c) 2015年 李欢. All rights reserved.
//

#import "LeftViewController.h"
#import "Masonry.h"
#import "ViewController.h"
#import "AboutUsViewController.h"
#import "YRSideViewController.h"
#import "AppDelegate.h"
#import "HistoryViewController.h"
#import "HHAlertView.h"

#define LEFT (self.view.frame.size.width / 3 * 2 - 80) / 2

@interface LeftViewController ()
@property (strong,nonatomic) YRSideViewController *sideViewController;


@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self startView];
    
    
    // Do any additional setup after loading the view.
}

- (void)startView
{
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/ 3 * 2, [UIScreen mainScreen].bounds.size.height)];
    image.image = [UIImage imageNamed:@"201fd4e0683e32f919252f4f277b035e.jpg"];
    image.userInteractionEnabled = YES;
    [self.view addSubview:image];
//    self.userImage = [[UIImageView alloc] init];
//    [self.userImage setBackgroundColor:[UIColor colorWithRed:0.282 green:0.409 blue:1.000 alpha:1.000]];
//    [self.view addSubview:self.userImage];
//    NSLog(@"x = %f", self.view.frame.size.width);
//    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left).offset(LEFT);
//        make.top.equalTo(self.view.mas_top).offset(50);
//        make.width.mas_equalTo(@80);
//        make.height.mas_equalTo(@80);
//    }];
//    self.userImage.layer.cornerRadius = 40;
//    self.userImage.userInteractionEnabled = YES;
//    self.userImage.clipsToBounds = YES;
//    
//    
//    self.userLable = [[UILabel alloc] init];
//    [self.userLable setBackgroundColor:[UIColor colorWithRed:0.282 green:0.409 blue:1.000 alpha:1.000]];
//    self.userLable.font = [UIFont systemFontOfSize:14];
//
//     [self.view addSubview:self.userLable];
//    [self.userLable mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left).offset(LEFT);
//        make.top.equalTo(self.view.mas_top).offset(140);
//        make.width.mas_equalTo(@80);
//        make.height.mas_equalTo(@30);
//    }];
    
    
    UIButton *button1 = [[UIButton alloc] init];
//    [button1 setBackgroundColor:[UIColor colorWithRed:0.282 green:0.409 blue:1.000 alpha:1.000]];
    button1.titleLabel.font = [UIFont systemFontOfSize:21];
    [button1 setTitle:@"首页" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(buttonAction1:) forControlEvents:UIControlEventTouchUpInside];

    [image addSubview:button1];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(LEFT - 30);
        make.top.equalTo(self.view.mas_top).offset(100);
        make.width.mas_equalTo(@150);
        make.height.mas_equalTo(@40);
    }];
    
    
    UIButton *button2 = [[UIButton alloc] init];
    //    [button1 setBackgroundColor:[UIColor colorWithRed:0.282 green:0.409 blue:1.000 alpha:1.000]];
    button2.titleLabel.font = [UIFont systemFontOfSize:21];
    [button2 setTitle:@"我的收藏" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(buttonAction2:) forControlEvents:UIControlEventTouchUpInside];
    
    [image addSubview:button2];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(LEFT - 30);
        make.top.equalTo(self.view.mas_top).offset(190);
        make.width.mas_equalTo(@150);
        make.height.mas_equalTo(@40);
    }];
    
    
    UIButton *button3 = [[UIButton alloc] init];
    //    [button1 setBackgroundColor:[UIColor colorWithRed:0.282 green:0.409 blue:1.000 alpha:1.000]];
    button3.titleLabel.font = [UIFont systemFontOfSize:21];
    [button3 setTitle:@"清除缓存" forState:UIControlStateNormal];
    [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(buttonAction3:) forControlEvents:UIControlEventTouchUpInside];

    
    [image addSubview:button3];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(LEFT - 30);
        make.top.equalTo(self.view.mas_top).offset(280);
        make.width.mas_equalTo(@150);
        make.height.mas_equalTo(@40);
    }];
    
    
//    UIButton *button4 = [[UIButton alloc] init];
//    //    [button1 setBackgroundColor:[UIColor colorWithRed:0.282 green:0.409 blue:1.000 alpha:1.000]];
//    button4.titleLabel.font = [UIFont systemFontOfSize:21];
//    [button4 setTitle:@"清除缓存" forState:UIControlStateNormal];
//    [button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [button4 addTarget:self action:@selector(buttonAction3:) forControlEvents:UIControlEventTouchUpInside];
//    
//    
//    [image addSubview:button4];
//    [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left).offset(LEFT - 30);
//        make.top.equalTo(self.view.mas_top).offset(370);
//        make.width.mas_equalTo(@150);
//        make.height.mas_equalTo(@40);
//    }];




}


- (void)buttonAction3:(id)sender
{
    
    ViewController *view = [[ViewController alloc] init];
    UINavigationController *naviagation = [[UINavigationController alloc]initWithRootViewController:view];
    //跳转风格动画
    view.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    
    YRSideViewController *sideViewController=[delegate sideViewController];
    
    view.navigationController.navigationBar.translucent = NO;
    view.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(itemAction:)];
    sideViewController.rootViewController = naviagation;
    [sideViewController hideSideViewController:YES];
    sideViewController.leftViewShowWidth = [UIScreen mainScreen].bounds.size.width / 3 * 2;;
    sideViewController.needSwipeShowMenu = true;//默认开启的可滑动展示
    [sideViewController.rootViewController.navigationController pushViewController:view animated:YES];
    
    NSFileManager *manager = [NSFileManager defaultManager];
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *path = [array lastObject];
    path = [NSString stringWithFormat:@"%@/Caches", path];
    NSLog(@"%@",path);
    BOOL judge = [manager fileExistsAtPath:path];
    if (judge) {
        [manager removeItemAtPath:path error:nil];
        
        [HHAlertView showAlertWithStyle:HHAlertStyleOk inView:view.view Title:@"Success" detail:@"清除缓存成功!" cancelButton:nil Okbutton:@"Sure" block:^(HHAlertButton buttonindex) {
            if (buttonindex == HHAlertButtonOk) {
                NSLog(@"ok Button is seleced use block");
            }
            else
            {
                NSLog(@"cancel Button is seleced use block");
            }
        }];
    }
    if (!judge) {
        [HHAlertView showAlertWithStyle:HHAlertStyleWraning inView:view.view Title:@"Wraing" detail:@"缓存为空" cancelButton:nil Okbutton:@"Sure"];
        
    }

}
- (void)buttonAction1:(id)sender
{
    ViewController *view = [[ViewController alloc] init];
    UINavigationController *naviagation = [[UINavigationController alloc]initWithRootViewController:view];
    //跳转风格动画
    view.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    
    YRSideViewController *sideViewController=[delegate sideViewController];
    
    view.navigationController.navigationBar.translucent = NO;
    view.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(itemAction:)];
    sideViewController.rootViewController = naviagation;
    [sideViewController hideSideViewController:YES];
    sideViewController.leftViewShowWidth = [UIScreen mainScreen].bounds.size.width / 3 * 2;;
    sideViewController.needSwipeShowMenu = true;//默认开启的可滑动展示
    [sideViewController.rootViewController.navigationController pushViewController:view animated:YES];
}

- (void)buttonAction2:(id)sender
{
    HistoryViewController *about = [[HistoryViewController alloc] init];
    UINavigationController *naviagation = [[UINavigationController alloc]initWithRootViewController:about];
    //跳转风格动画
    about.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    
    YRSideViewController *sideViewController=[delegate sideViewController];
    
    about.navigationController.navigationBar.translucent = NO;
    about.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(itemAction:)];
    sideViewController.rootViewController = naviagation;
    [sideViewController hideSideViewController:YES];
    sideViewController.leftViewShowWidth = [UIScreen mainScreen].bounds.size.width / 3 * 2;;
    sideViewController.needSwipeShowMenu = true;//默认开启的可滑动展示
    [sideViewController.rootViewController.navigationController pushViewController:about animated:YES];
}

- (void)itemAction:(id)sender{
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    
    [delegate.sideViewController showLeftViewController:NO];
    NSLog(@"还没做抽屉");
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
